//
//  ShopActivityView.m
//  TestPrj
//
//  Created by 朱铅峰 on 2020/6/23.
//  Copyright © 2020 Xing. All rights reserved.
//

#import "ShopActivityView.h"

@implementation ShopActivityView

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self addViews];
    }
    return self;
}

- (void)addViews {
    
    CGFloat max_Y = 0;
    self.contentSize = CGSizeMake(self.width, 1000);
    self.showsVerticalScrollIndicator = NO;
    self.bounces = YES;
    
    //间隔
    UIView *lineLab = [[UIView alloc] initWithFrame: CGRectMake(0, 88, self.width, 10)];
    lineLab.backgroundColor = kColorGray;
    [self addSubview:lineLab];
    
    max_Y = lineLab.bottom;
    
    //*******************************优惠券活动************************************
    
    UIScrollView *couponScorllView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, lineLab.bottom, self.width, 100)];
    couponScorllView.showsHorizontalScrollIndicator = NO;
    [self addSubview:couponScorllView];
    
    for (int i = 0; i<3; i++) {
        UIView *couponView = [[UIView alloc]initWithFrame:CGRectMake(10+(210 + 20)*i, 10, 210, 80)];
        [couponScorllView addSubview:couponView];
        //优惠券图片
        UIImageView *couponImgView = [[UIImageView alloc]init];
        couponImgView.frame = couponView.bounds;
        couponImgView.tag = 50;
        couponImgView.image = [UIImage imageNamed:@"bg_coupon_red"];
        if (arc4random()%6==0) {
            couponImgView.image = [UIImage imageNamed:@"bg_coupon_yellow"];
        }
        
        [couponView addSubview:couponImgView];
        //优惠券价格
        UILabel *priceLab = [Utils genLabelWithFrame:CGRectMake(14, 9, 100, 20) textAlign:NSTextAlignmentLeft fontSize:20 textColor:[UIColor redColor]];
        priceLab.text = [NSString stringWithFormat:@"¥%@",@"5"];
        [couponView addSubview:priceLab];
        //满多少钱可用
        UILabel *moreThanLab = [Utils genLabelWithFrame:CGRectMake(14, 40, 100, 14) textAlign:NSTextAlignmentLeft fontSize:14 textColor:[UIColor orangeColor]];
        moreThanLab.text = [NSString stringWithFormat:@"满%@可用",@"50"];
        [couponView addSubview:moreThanLab];
        //时间
        
        UILabel *timeLab = [Utils genLabelWithFrame:CGRectMake(14, 59, 140, 10) textAlign:NSTextAlignmentLeft fontSize:10 textColor:[UIColor orangeColor]];
        timeLab.text = [NSString stringWithFormat:@"%@前使用",@"2020-12-12 00:00:00"];
        [couponView addSubview:timeLab];
        //领取
        UILabel *getLab = [Utils genLabelWithFrame:CGRectMake(couponView.width-4-60, 0, 60, 80) textAlign:NSTextAlignmentCenter fontSize:16 textColor:[UIColor whiteColor]];
        getLab.text = @"立即\n领取";
        if (arc4random()%6==0) {
            getLab.text = @"已使用";
        }
        getLab.tag = 51;
        [couponView addSubview:getLab];
        
        [couponScorllView setContentSize:CGSizeMake(couponView.right+20, 100)];
    }
    
    UIView *lineLab2 = [[UIView alloc] initWithFrame:CGRectMake(0, couponScorllView.bottom, self.width, 10)];
    lineLab2.backgroundColor = kColorGray;
    [self addSubview:lineLab2];
    
    max_Y = lineLab2.bottom;
    
    
    
    //*******************************满减活动************************************
    
    UIView *activityView2 = [[UIView alloc]initWithFrame:CGRectMake(0, max_Y, self.width, 36)];
    [self addSubview:activityView2];
    //
    for (int i = 0; i<10; i++) {
        
        NSInteger type = 1+arc4random()%3;
        
        UIImageView *iconView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13+(14+11)*i, 14, 14)];
        //1.限时折扣  2.满减  3.优惠券
        if (type == 1) {
            iconView.image = [UIImage imageNamed:@"icon-discounts"];
        } else if (type == 2) {
            iconView.image = [UIImage imageNamed:@"icon-sale"];
        } else if (type == 3) {
            iconView.image = [UIImage imageNamed:@"icon-coupons"];
        }
        [activityView2 addSubview:iconView];
        //活动名称
        UILabel *activityLab = [Utils genLabelWithFrame:CGRectZero textAlign:NSTextAlignmentLeft fontSize:12 textColor:kColorLightGray];
        activityLab.text = [NSString stringWithFormat:@"活动%d",i];
        activityLab.frame = CGRectMake(iconView.right+10, 15+(12+11)*i, self.width-(iconView.right+10+60), 12);
        [activityView2 addSubview:activityLab];
        
        activityView2.height = activityLab.bottom+11;
    }
    //
    UIImageView *nextImgView = [[UIImageView alloc]initWithFrame:CGRectMake(self.width-20, 13, 10, 10)];
    nextImgView.image = [UIImage imageNamed:@"icon_up_black"];
    [activityView2 addSubview:nextImgView];
    
    UIControl *foldingBT = [[UIControl alloc]init];
    [foldingBT addTarget:self action:@selector(moveUpClick) forControlEvents:UIControlEventTouchUpInside];
    foldingBT.frame = CGRectMake(activityView2.right-50, 0, 50, activityView2.height);
    [activityView2 addSubview:foldingBT];
    
    UIView *lineLab3 = [[UIView alloc] initWithFrame:CGRectMake(0, activityView2.bottom, self.width, 0.5)];
    lineLab3.backgroundColor = kColorGray;
    [self addSubview:lineLab3];
    
    max_Y = lineLab3.bottom;
    
    
    //营业时间
    UILabel *textLab = [Utils genLabelWithFrame:CGRectMake(10, max_Y+10, self.width, 14) textAlign:NSTextAlignmentLeft fontSize:14 textColor:kColorGray];
    [self addSubview:textLab];
    textLab.text = @"营业时间";
    
    UILabel *timeLab = [Utils genLabelWithFrame:CGRectMake(10, textLab.bottom+10, self.width, 12) textAlign:NSTextAlignmentLeft fontSize:12 textColor:kColorGray];
    timeLab.text = @"09:00";
    [self addSubview:timeLab];
    
    max_Y = timeLab.bottom;
    
    //公告
    UILabel *noticeLab = [Utils genLabelWithFrame:CGRectMake(10, max_Y+15, 42, 14) textAlign:NSTextAlignmentLeft fontSize:14 textColor:kColorGray];
    noticeLab.text = @"公告:";
    [self addSubview:noticeLab];
    
    UILabel *contentLab = [Utils genLabelWithFrame:CGRectMake(10, noticeLab.bottom+10, self.width-20, 12) textAlign:NSTextAlignmentLeft fontSize:12 textColor:kColorGray];
    [self addSubview:contentLab];
    NSString *text = @"耷拉到了发了发额监理费阿尔拉企鹅涪陵区饿疯了企鹅浪费钱就饿了父亲节额父亲节企鹅福利企鹅父亲节额父亲节俄方企鹅放弃阿胶费力气就饿疯了企鹅企鹅放弃俄方企鹅放弃俄方将全额分起飞企鹅费力气减肥期间额放弃；额放弃俄方企鹅解放了企鹅解放前额放弃；废弃；额放弃额风景区附近企鹅分";
    if (text.length == 0||!text) {
        text = @"暂无公告";
    }
    contentLab.text = text;
    contentLab.font = [UIFont systemFontOfSize:12];
    contentLab.numberOfLines = 0;
    contentLab.width = self.width - (noticeLab.bottom+20);
    contentLab.height = [Utils textSizeOfText:text fontSize:12 width:contentLab.width].height;
    
    self.contentSize = CGSizeMake(self.width, contentLab.bottom+10);
}

- (void)moveUpClick {
    
    if (self.moveUpAction) {
        self.moveUpAction();
    }
}

@end
